package com.west.common.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.LinearLayout;

import com.west.common.uitils.UiUtil;

/**
 * @author hanyulang
 * @date 2018/12/3
 */
public class TitleBarAbstract extends LinearLayout {

    public TitleBarAbstract(Context context) {
        super(context);
        init(null);
    }

    public TitleBarAbstract(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(attrs);
    }

    public TitleBarAbstract(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(attrs);
    }

    protected void init(AttributeSet attrs){
        setPadding(getLeft() + getPaddingLeft(), getTop() + UiUtil.getStatusBarHeight(getContext()), getRight() + getPaddingRight(), getBottom());
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        float d = getResources().getDisplayMetrics().density;
        int minH = (int) (d * 40 + UiUtil.getStatusBarHeight(getContext()));

        heightMeasureSpec = MeasureSpec.makeMeasureSpec(minH, MeasureSpec.EXACTLY);

        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

}
